package cn.cboard.dao.sql;

import java.sql.ResultSet;
import java.sql.SQLException;

import cn.cboard.database.RowMapper;
import cn.cboard.model.Forum;
import cn.cboard.model.ForumThread;
import cn.cboard.model.ForumTopic;
import cn.cboard.model.User;

public class TopicMapper implements RowMapper{

	public Object mapRow(ResultSet rs) throws SQLException {
		ForumTopic forumTopic =  new ForumTopic();
		
		forumTopic.setTopicId(rs.getLong("topicId"));
		forumTopic.setSubject(rs.getString("subject"));
		
		forumTopic.setModifiedDate(rs.getDate("modifiedDate"));
		forumTopic.setCreationDate(rs.getDate("creationDate"));
		forumTopic.setContent(rs.getString("content"));
		
		Forum forum = new Forum();
		forum.setForumId(rs.getLong("forumId"));
		forumTopic.setForum(forum);
		
		ForumThread thread = new ForumThread();
		thread.setThreadId(rs.getLong("threadId"));
		forumTopic.setForumThread(thread);
		
		User user = new User();
		user.setUserId(rs.getLong("userId"));
		forumTopic.setUser(user);
		
		return forumTopic;
	}

}
